home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / docs / misc / ConcNews.lha / news / amiga.programming / comp.sys.amiga.programmer_30613_000017.msg < prev    next >
Encoding:
Text File  |  1994-11-27  |  3.1 KB  |  90 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: cs.chalmers.se!news.chalmers.se!sunic!uunet!europa.eng.gtefsd.com!darwin.sura.net!news-feed-1.peachnet.edu!concert!sas!mozart.unx.sas.com!walker
  3. From: walker@twix.unx.sas.com (Doug Walker)
  4. Subject: Re: Exec RawDoFmt
  5. Originator: walker@twix.unx.sas.com
  6. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  7. Message-ID: <C6xCB7.3CG@unx.sas.com>
  8. Date: Wed, 12 May 1993 17:23:30 GMT
  9. References: <C6v9wr.CvH@unx.sas.com> <1993May12.133954.3498@imada.ou.dk>
  10. Nntp-Posting-Host: twix.unx.sas.com
  11. Organization: SAS Institute Inc.
  12. Lines: 77
  13.  
  14.  
  15. In article <1993May12.133954.3498@imada.ou.dk>, breese@monet.imada.ou.dk (Bjorn Reese) writes:
  16. |> > In article <Miles_Willmek.0jfy@saug.UUCP>, Miles_Willmek@saug.UUCP (Miles  
  17. |> Willmek) writes:
  18. |> > >Can somebody help me with Exec's RawDoFmt() function.  I cant seem to get
  19. |> > >string types (%s, %b)to output anything (except spaces if I specify a field
  20. |> > >width.
  21. |> > >
  22. |> > >I'm pretty sure its not my code.  Does RawDoFmt() work?
  23. |> 
  24. |> The parameter for %s (strings) must be a pointer to the string,
  25. |> not the string itself, as in Printf().
  26.  
  27. The "string itself" and the "pointer to the string" are actually the
  28. same thing in C.  A string literal is really a char * that points to
  29. the beginning of the string.  Hence, the parameter for %s is the same
  30. for Printf() and RawDoFmt().
  31.  
  32. Here is example code that uses RawDoFmt() to print a string and a
  33. decimal value.  BE CAREFUL when printing integers if you use four-byte
  34. integers (the default for SAS/C and most other compilers) - unlike 
  35. normal C, you must use %ld instead of %d when printing "int" variables
  36. and constants if you use RawDoFmt().
  37.  
  38. #include <stdarg.h>
  39. #include <string.h>
  40. #include <clib/dos_protos.h>
  41. #include <clib/exec_protos.h>
  42. #include <pragmas/dos_pragmas.h>
  43. #include <pragmas/exec_pragmas.h>
  44.  
  45. extern struct Library *DOSBase;
  46.  
  47. int myprintf(char *ctl, ...);
  48.  
  49. int main(void)
  50. {
  51.    myprintf("This is a %s (%ld)\n", "test", 42);
  52.    return 0;
  53. }
  54.  
  55. int myprintf(char *ctl, ...)
  56. {
  57.    char buffer[256];
  58.    va_list args;
  59.  
  60.    va_start(args, ctl);
  61.  
  62.    /*********************************************************/
  63.    /* NOTE: The string below is actually CODE that copies a */
  64.    /*       value from d0 to A3 and increments A3:          */
  65.    /*                                                       */
  66.    /*          move.b d0,(a3)+                              */
  67.    /*          rts                                          */
  68.    /*                                                       */
  69.    /*       It is essentially the callback routine needed   */
  70.    /*       by RawDoFmt.                                    */
  71.    /*********************************************************/
  72.  
  73.    RawDoFmt(ctl, args, (void (*))"\x16\xc0\x4e\x75", buffer);
  74.  
  75.    va_end(args);
  76.  
  77.    Write(Output(), buffer, strlen(buffer));
  78.  
  79.    return 0;
  80. }
  81.  
  82.  
  83. -- 
  84.   *****                    / walker@unx.sas.com
  85.  *|_o_o|\\     Doug Walker<  BIX, Portal: djwalker
  86.  *|. o.| ||                \ CompuServe: 71165,2274
  87.   | o  |//     
  88.   ====== 
  89. Any opinions expressed are mine, not those of SAS Institute, Inc.
  90.